<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/9/5
 * Time: 11:07
 */

namespace app\index\service;

use think\Db;
use think\Exception;
class ProductService
{
    /**
     * @Notes:用于对单张表格进行简单的select操作
     * @return array
     * @author: LiBaoJin
     * @Time:
     */
    public static function table_select($table_name,$where)
    {
        try{
            $data =  Db::table($table_name)
                ->where($where)
                ->select();
            return 	DataReturnService::returnOk($data,'ok');
        }catch(Exception$e){
            return  DataReturnService::returnError(-1,$e->getMessage());
        }
    }

    public static function store_list($user_id) {
        try{
            $store = Db::table('staff')
                ->join('store','staff.store_id = store.id','LEFT')
                ->where(['staff.business_id'=>$user_id,'staff.state'=>0])
                ->field('staff.user_id,staff.store_id,staff.name,store.store_name')
                ->select();
            return DataReturnService::returnOk(self::set_array($store),'ok');
        }catch(Exception$e){
            return  DataReturnService::returnError(-1,$e->getMessage());
        }

    }
    public static function set_array($store){
        $list=[];
        if(!is_array($store)){
            return $list;
        }
        foreach($store as $k=>$v){
            $list[$v['store_id']][]= $v;
        }
        return $list;
    }
}